package com.peng._05mvcboot02.common.exception;

import com.peng._05mvcboot02.common.response.JsonResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 * @Author peng
 * @Date 2024-04-26 10:49
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler
    public JsonResult handleIllegalArgumentException(IllegalArgumentException e) {
        return JsonResult.error("输入参数非法", e.getMessage());
    }

    @ExceptionHandler
    public JsonResult handleRuntimeException(RuntimeException e) {
        return JsonResult.error("系统运行异常", e.getMessage());
    }

    public JsonResult handleThrowableException(Throwable e) {
        return JsonResult.error("系统产生未知异常", e.getMessage());
    }

}
